
/**
 * base64 tool mgr;
 * base64_for_str : str base64;
 * base64_for_na : number arrays base64;
 */
var tool = cc.Class({
    extends: cc.Component,

    properties: {
        
    },
    init:function()
    {
        this._base64_for_str = require("base64_for_str");
        this._base64_for_na = require("base64_for_na");
    },
    //////////////n a related///////////
    encode_na:function(buffer, start, end)
    {
        var encoded_str = this._base64_for_na.encode(buffer, start, end);
        return encoded_str;
    },
    decode_na:function(string, buffer, offset)
    {
        this._base64_for_na.decode(string, buffer, offset);
    },

    /////////////str related/////////////
    encode:function(str)
    {
        var encoded_str = this._base64_for_str.encode(str);
        return encoded_str;
    },
    decode:function(base64Str)
    {
        var decoded_str = this._base64_for_str.decode(base64Str);
        return decoded_str;
    },
    urlsafe_encode:function(str)
    {
        var encoded_str = this._base64_for_str.urlsafe_encode(str);
        return encoded_str;
    },
    urlsafe_decode:function(base64Str)
    {
        var decoded_str = this._base64_for_str.urlsafe_decode(base64Str);
        return decoded_str;
    },

    ///////////////
    // test:function()
    // {
    //     var arraybuffer = new ArrayBuffer(8);
    //     var aView = new Uint8Array(arraybuffer, 0, 7);
    //     aView[0] = 1;
    //     aView[1] = 0;
    //     aView[2] = 1;
    //     var encoded_str = cc.vv.base64Tool.encode_na(aView, 0, aView.length);
    //     var buffer = new ArrayBuffer(8);
    //     cc.vv.base64Tool.decode_na(encoded_str, buffer, arraybuffer.length);

    //     var raw_str = "balabala";
    //     var encoded_str = cc.vv.base64Tool.urlsafe_encode(raw_str);
    //     var decoded_str = cc.vv.base64Tool.urlsafe_decode(encoded_str);
    // }
});
module.exports = new tool();